package pruebas;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Prueba {

	/**
	 * @param args
	 * @throws SQLException 
	 * @throws ClassNotFoundException 
	 */
	public static void main(String[] args) throws SQLException, ClassNotFoundException {
		new Prueba().getDBConnection();

	}

	String jdbcUrl="jdbc:oracle:thin:@juanitu:1521:XE" ;
			//	String jdbcUrl = "jdbc:oracle:thin:@localhost";
	    Connection conn2; 
	    public void getDBConnection() throws SQLException, ClassNotFoundException {
//	        OracleDataSource ds;
//	        ds = new OracleDataSource();
//	        ds.setURL(jdbcUrl);
//	        conn2 = ds.getConnection(userid, password);
//	        tiger

	        Class.forName("oracle.jdbc.driver.OracleDriver");
//	        Connection conn = DriverManager.getConnection(jdbcUrl, "juan", "root");  
	        Connection conn = DriverManager.getConnection(jdbcUrl,"juan", "root");
	        System.out.println("por fin!!");
//	        conn.setAutoCommit(false);
	        Statement stmt = conn.createStatement();
	        String s;
	        s="CREATE table \"OVARIOS\" ( "+
	        	    "\"ID\"         NUMBER NOT NULL, "+
	        	    "\"NOMBRE\"     VARCHAR2(4000) NOT NULL, "+
	        	    "constraint  \"OVARIOS_PK\" primary key (\"ID\") "+
	        	")";
	        stmt.executeUpdate(s);
	        s="CREATE SEQUENCE   \"OVARIOS_SEQ\"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ";
	        stmt.executeUpdate(s);
	        s ="CREATE OR REPLACE TRIGGER  \"BI_OVARIOS\""+ 
	        "before insert on \"OVARIOS\""+               
	        "for each row  "+
	      "begin"+   
	       " select \"OVARIOS_SEQ\".nextval into :NEW.ID from dual;"+ 
	      "end; ";
	        stmt.executeUpdate(s);
	        s = "DROP sequence \"OVARIOS_SEQ\"";
	        stmt.executeUpdate(s);
	        s = "DROP TABLE \"OVARIOS\"";
	        stmt.executeUpdate(s);
//	        conn.commit();
	        
	        
	    }




}
